home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / Integer.sig < prev    next >
Encoding:
Text File  |  1996-07-03  |  3.9 KB  |  125 lines  |  [TEXT/R*ch]

  1. (* Integer -- SML Standard Library *)
  2.  
  3. type int = int
  4.  
  5. val precision : int option
  6. val minint    : int option
  7. val maxint    : int option
  8.  
  9. val ~    : int -> int
  10. val *    : int * int -> int
  11. val div  : int * int -> int 
  12. val mod  : int * int -> int 
  13. val quot : int * int -> int 
  14. val rem  : int * int -> int 
  15. val +    : int * int -> int
  16. val -    : int * int -> int
  17. val >    : int * int -> bool
  18. val >=   : int * int -> bool
  19. val <    : int * int -> bool
  20. val <=   : int * int -> bool
  21. val abs  : int -> int
  22. val min  : int * int -> int
  23. val max  : int * int -> int
  24. val sign : int -> int
  25. val compare : int * int -> ordering
  26.  
  27. val sameSign    : int * int -> bool
  28. val toDefault   : int -> int
  29. val fromDefault : int -> int
  30.  
  31. val floor : real -> int
  32. val ceil  : real -> int
  33. val trunc : real -> int
  34. val round : real -> int
  35. val real  : int -> real
  36.  
  37. val toString   : int -> string
  38. val fromString : string -> int option
  39. val scan : StringCvt.radix -> {getc : 'a -> (char * 'a) option} 
  40.            -> 'a -> (int * 'a) option
  41. val fmt  : StringCvt.radix -> int -> string
  42.  
  43. (* [precision] is SOME n, where n is the number of significant bits in an
  44.    integer.  In Moscow ML n is 31 in 32-bit architectures and 63 in 64-bit
  45.    architectures.
  46.  
  47.    [minint] is SOME n, where n is the most negative integer.
  48.  
  49.    [maxint] is SOME n, where n is the most positive integer.
  50.  
  51.    [~, *, div, mod, +, -, >, >=, <, <=, abs] are the usual operations
  52.    on integers, as prescribed by the Definition.
  53.  
  54.    [quot(i, d)] is the quotient of i by d, rounding towards zero (instead 
  55.    of rounding towards minus infinity, as done by div).
  56.  
  57.    [rem(i, d)] is the remainder for quot.  That is, if 
  58.            q' = i quot d  and  r' = i rem d
  59.    then 
  60.            d * q' + r' = i
  61.    and     0 <= d * q' <= i  or  i <= d * q' <= 0.
  62.    
  63.    [min(x, y)] is the smaller of x and y.
  64.  
  65.    [max(x, y)] is the larger of x and y.
  66.  
  67.    [sign x] is ~1, 0, or 1, according as x is negative, zero, or positive.
  68.  
  69.    [compare(x, y)] returns LESS, EQUAL, or GREATER, according 
  70.    as x is less than, equal to, or greater than y.
  71.  
  72.    [sameSign(x, y)] is true iff sign x = sign y.
  73.  
  74.    [toDefault x] is x.
  75.  
  76.    [fromDefault x] is x.
  77.  
  78.    [floor r] is the largest integer <= r (rounds towards minus infinity).
  79.  
  80.    [ceil r] is the smallest integer >= r (rounds towards plus infinity).
  81.  
  82.    [trunc r] is numerically largest integer between r and zero 
  83.    (rounds towards zero).
  84.  
  85.    [round r] is the integer nearest to r.  In case of a tie, rounds to 
  86.    nearest numerically larger integer.  NOTE: This isn't the required
  87.    behaviour: it should round to nearest even integer in case of a tie.
  88.  
  89.    [real i] is the real representing the same value as i.
  90.  
  91.    [fmt radix i] returns a string representing i, in the radix (base)
  92.    specified by radix.
  93.  
  94.      radix    description                    
  95.      -------------------------------------
  96.       BIN     signed binary      (base  2) 
  97.       OCT     signed octal       (base  8)   
  98.       DEC     signed decimal     (base 10)   
  99.       HEX     signed hexadecimal (base 16)   
  100.  
  101.    [toString i] returns a string representing i in signed decimal format.
  102.    Equivalent to (fmt DEC i).
  103.    
  104.    [fromString s] returns SOME(i) if a decimal integer numeral can be
  105.    scanned from a prefix of string s, ignoring any initial whitespace;
  106.    returns NONE otherwise.  A decimal integer numeral must have form,
  107.    after possible initial whitespace: 
  108.     [+~-]?[0-9]+
  109.  
  110.    [scan radix {getc} charsrc] attempts to scan an integer numeral
  111.    from the character source charsrc, using the accessor getc, and
  112.    ignoring any initial whitespace.  The radix argument specifies the base
  113.    of the numeral (BIN, OCT, DEC, HEX).  If successful, it returns
  114.    SOME(i, rest) where i is the value of the number scanned, and rest
  115.    is the unused part of the character source.  A numeral must have
  116.    form, after possible initial whitespace:
  117.  
  118.      radix    format 
  119.      ---------------------------
  120.       BIN     [+~-]?[0-1]+
  121.       OCT     [+~-]?[0-7]+
  122.       DEC     [+~-]?[0-9]+
  123.       HEX     [+~-]?[0-9a-fA-F]+
  124. *)
  125.